<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        canvas {
            border: 1px solid #ccc;
        }
    </style>
</head>
<body>
<canvas width="600" height="400"></canvas>
<script>
    var myCanvas = document.querySelector('canvas');
    var ctx = myCanvas.getContext('2d');

    /*绘制*/
    /*ctx.moveTo(100,100);
    ctx.lineTo(355,100);
    ctx.lineWidth = 30;
    /!*颜色的填充*!/
    ctx.strokeStyle = '#fff';
    /!*从黑到白的渐变颜色*!/
    ctx.stroke();*/

    /*线是由点构成的*/
    ctx.lineWidth = 30;
    ctx.moveTo(100,100);
    for (let i = 0; i < 255; i++) {
        ctx.beginPath();
        ctx.moveTo(100+i-1,100);
        ctx.lineTo(101+i,100);
        ctx.strokeStyle = 'rgb('+i+','+i+','+i+')'
        ctx.stroke();
    }

</script>
</body>
</html>
